package com.fishery.monitor.controller;

import com.fishery.entity.Result;
import com.fishery.entity.StatusCode;
import com.fishery.monitor.pojo.Equipment;
import com.fishery.monitor.service.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 控制器层
 * @author Administrator
 *
 */
@Api(tags = "设备接口")
@RestController
@CrossOrigin
@RequestMapping("/equipment")
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentService;


    /**
     * 根据基地id和typeId查询所有设备,分页
     */
    @ApiOperation("根据基地id和typeId查询所有设备,分页")
    @RequestMapping(value="/findAllByBaseId/{baseId}/{typeId}/{page}/{size}",method= RequestMethod.GET)
    public Result findAllByBaseId(@PathVariable String baseId, @PathVariable String typeId, @PathVariable int page, @PathVariable int size){
        return new Result(true,StatusCode.OK,"查询成功", equipmentService.findAllByBaseId(baseId, typeId, page, size));
    }

    //根据基地id查询池塘调用溯源模块的接口就好了

    /**
     * 查询全部数据
     * @return
     */
    @ApiOperation("查询全部数据")
    @RequestMapping(method= RequestMethod.GET)
    public Result findAll(){
        return new Result(true,StatusCode.OK,"查询成功", equipmentService.findAll());
    }

    /**
     * 根据ID查询
     * @param id ID
     * @return
     */
    @ApiOperation("根据ID查询")
    @RequestMapping(value="/{id}",method= RequestMethod.GET)
    public Result findById(@PathVariable String id){
        return new Result(true,StatusCode.OK,"查询成功", equipmentService.findById(id));
    }


    /**
     * 分页+多条件查询
     * @param searchMap 查询条件封装
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @ApiOperation("分页+多条件查询")
    @RequestMapping(value="/search/{page}/{size}",method= RequestMethod.POST)
    public Result findSearch(@RequestBody @ApiParam(name = "查询条件，属性：值 形式",required = true,value = "searchMap") Map searchMap , @PathVariable int page, @PathVariable int size){
        return  new Result(true,StatusCode.OK,"查询成功",  equipmentService.findSearch(searchMap, page, size) );
    }

    /**
     * 根据条件查询
     * @param searchMap
     * @return
     */
    @RequestMapping(value="/search",method = RequestMethod.POST)
    public Result findSearch( @RequestBody Map searchMap){
        return new Result(true,StatusCode.OK,"查询成功", equipmentService.findSearch(searchMap));
    }

    /**
     * 增加
     * @param equipment
     */
    @ApiOperation("增加")
    @RequestMapping(method= RequestMethod.POST)
    public Result add(@RequestBody @ApiParam(name = "设备对象",required = true,value = "equipment") Equipment equipment){
        equipmentService.add(equipment);
        return Result.success("增加成功");
    }

    /**
     * 修改
     * @param equipment
     */
    @ApiOperation("修改")
    @RequestMapping(value="/{id}",method= RequestMethod.PUT)
    public Result update(@RequestBody @ApiParam(name = "设备对象",required = true,value = "equipment") Equipment equipment, @PathVariable String id ){
        equipment.setId(id);
        equipmentService.update(equipment);
        return Result.success("修改成功");
    }

    /**
     * 删除
     * @param id
     */
    @ApiOperation("删除")
    @RequestMapping(value="/{id}",method= RequestMethod.DELETE)
    public Result delete(@PathVariable String id ){
        equipmentService.deleteById(id);
        return Result.success("删除成功");
    }

}
